import axios from 'axios'

export interface CreateTaskRequest {
  title: string
  description: string
  prompt: string
  version: string
  judges: string[]
  models: string[]
  questionIds: number[]
}

export interface EvaluationTask {
  id: number
  prompt: string
  version: string
  judges: string[]
  models: string[]
  questionIds: number[]
  status: 'pending' | 'running' | 'completed'
  createdAt: string
  updatedAt: string
}
export interface GetTasksResponse {
  id: number
  version: string
  status: string
  time: Date
  title: string
  description: string
  prompt: string
  judges: string[]
  models: string[]
  questionIds: number[]
}

export async function createTask(taskData: CreateTaskRequest): Promise<void> {
  await axios.post('/api/eval/task', {
    title: taskData.title.slice(0, 50), // Use the first 50 characters of the prompt as the title
    description: taskData.description,
    prompt: taskData.prompt,
    version: taskData.version,
    judges: taskData.judges,
    models: taskData.models,
    questionIds: taskData.questionIds
  })
}

export async function runTask(taskId: number): Promise<void> {
  await axios.post(`/api/eval/task/${taskId}/run`)
}



export async function getTasks(version: string): Promise<GetTasksResponse[]> {
  const response = await axios.get(`/api/eval/tasks?version=${version}`)
  return response.data
}

export interface LlmAnswerResponse {
  id: number
  model: string
  answer: string
  time: string
  version: string
  question: {
    id: number
    version: string
    question: string
  }
}

export async function getTaskById(taskId: number): Promise<EvaluationTask> {
  const response = await axios.get(`/api/eval/task/${taskId}`)
  return response.data
}

export interface Evaluate {
  id: number
  singleReport: string
  judge: string
  active: boolean
}

export async function getTaskAnswers(taskId: number): Promise<LlmAnswerResponse[]> {
  const response = await axios.get(`/api/eval/task/${taskId}/answers`)
  console.log('获取任务答案API响应:', response.data)
  return response.data
}

export async function getAnswerEvaluates(answerId: number): Promise<Evaluate[]> {
  const response = await axios.get(`/api/eval/answer/${answerId}/evaluates`)
  return response.data
}